<template>
  <div class="app-container">
    <Ht-search-form
      v-show="showSearch"
      :advOptions="[]"
      :dictMap="dictMap"
      :formOptions="formOptions"
      :outputQueryParams="queryParams"
      :queryParams="queryParams"
      :defaultEventKey="defaultEventKey"
    ></Ht-search-form>

    <ht-table
      :defaultEventKey="defaultEventKey"
      ref="dataTable"
      :dictMap="dictMap"
      :multi-select="false"
      :opButtonList="opButtonList"
      :queryParams="queryParams"
      :reqConfig="regConfig"
      :showSerialNumber="false"
      :tableBindColumns="tableBindColumns"
    >
      <template v-slot:operate>
        <el-table-column align="left" fixed="right" label="操作" width="50">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '明细',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 添加或修改弹出框 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="title"
      center
      :visible.sync="open"
      v-if="open"
      append-to-body
      width="1024px"
    >
      <el-form ref="detailForm" :model="detailForm" :rules="rules" label-width="160px">
        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="交易流水号" prop="id">
              <el-input v-model="detailForm.id" disabled/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="报文类型" prop="msgType">
              <el-select style="width: 100%" v-model="detailForm.msgType" placeholder="报文类型" disabled>
                <el-option
                  v-for="dict in dictMap.PKG_TYPE"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="报文标识号" prop="pkgId">
              <el-input v-model="detailForm.pkgId" disabled/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="系统编号" prop="sysCode">
              <el-select style="width: 100%" v-model="detailForm.sysCode" placeholder="系统编号" disabled>
                <el-option
                  v-for="dict in dictMap.ORGAN_SYSTYPE_310"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工作日期" prop="workdate">
              <el-date-picker v-model="detailForm.workdate" style="width: 100%" type="date" value-format="yyyyMMdd" disabled/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="业务类型编码" prop="oriBizType">
              <el-select
                style="width: 100%"
                v-model="
                  detailForm.bizTypeCode === null || detailForm.bizTypeCode === undefined
                    ? ''
                    : detailForm.bizTypeCode + '-' + detailForm.bizTypeCodeDesc
                "
                placeholder="业务类型编码"
                :disabled="true"
              ></el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="业务种类编码" prop="bizCtgyCode">
              <el-select
                style="width: 100%"
                v-model="
                  detailForm.bizCtgyCode === null || detailForm.bizCtgyCode === undefined
                    ? ''
                    : detailForm.bizCtgyCode + '-' + detailForm.bizCtgyCodeDesc
                "
                placeholder="业务种类编码"
                :disabled="true"
              ></el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <ht-table
            ref="dataTable"
            :dictMap="dictMap"
            :multi-select="false"
            :opButtonList="opButtonList"
            :queryParams="queryParamsDetail"
            :reqConfig="regConfigDetail"
            :showSerialNumber="false"
            :tableBindColumns="tableBindColumnsDetail"
          ></ht-table>
        </el-row>
      </el-form>
      <div slot="footer" align="center" class="dialog-footer">
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPageMixin } from "@/libs/listPageMixin";
import HtAmountInput from "@/views/components/HtAmountInput";
import {
  apiUrlConfigDetailQuery,
  apiUrlConfigQuery,
  apiUrlConfigQueryDetail,
  ccmsBusinessDownloadApplyQueryDetail,
} from "@/api/cnaps/ccms/929";
export default {
  name: "ccmsBusinessDownloadApplyQuery",
  mixins: [listPageMixin],
  components: { HtAmountInput },
  data() {
    return {
      defaultEventKey: "defaultEventKey",
      // 查询参数
      queryParams: {
        id:"",
        workdate: "",
        workdate2: "",
      },

      queryParamsDetail: {},
      // 搜索
      formOptions: [],
      //
      searchFormDictList: ["ORGAN_SYSTYPE_310", "MNG_TYPE", "PKG_TYPE"],
      // 列信息
      regConfig: apiUrlConfigQuery,

      regConfigDetail: apiUrlConfigQueryDetail,

      rules: {},

      tableBindColumns: [
        { prop: "id", label: "交易流水号", width: 180 },
        { prop: "workdate", label: "工作日期", type: "date" },
        { prop: "sysCode", label: "系统编号", dictCode: "ORGAN_SYSTYPE_310", width: 180 },
        { prop: "msgType", label: "报文类型", dictCode: "PKG_TYPE", width: 180 },
        { prop: "oriId", label: "报文应答ID", width: 180 },
        {
          prop: "bizTypeCode",
          label: "业务类型编码",
          formatter(row, text, index) {
            return (
              (row["bizTypeCode"] === null || row["bizTypeCode"] === undefined ? "" : row["bizTypeCode"]) +
              "-" +
              (row["bizTypeCodeDesc"] === null || row["bizTypeCodeDesc"] === undefined ? "" : row["bizTypeCodeDesc"])
            );
          },
          width: 180,
        },
        {
          prop: "bizCtgyCode",
          label: "业务种类编码",
          formatter(row, text, index) {
            return (
              (row["bizCtgyCode"] === null || row["bizCtgyCode"] === undefined ? "" : row["bizCtgyCode"]) +
              "-" +
              (row["bizCtgyCodeDesc"] === null || row["bizCtgyCodeDesc"] === undefined ? "" : row["bizCtgyCodeDesc"])
            );
          },
        },
      ],

      tableBindColumnsDetail: [
        { prop: "id", label: "序号" },
        { prop: "btId", label: "原报文ID" },
        { prop: "directSendpl", label: "参与机构号" },
        { prop: "mngType", label: "管理类型", dictCode: "MNG_TYPE" },
      ],

      dictMapAsync: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,

      openDetail: false,
      // 表单参数
      detailForm: {
        pkgNo: undefined,
        pkgNoDesc: undefined,
      },
      totalRecord: 0,
      totalPage: 0,
      needCount: 0,
    };
  },
  mounted() {
    const formOptions = [
      // 普通搜索
      {
        type: "input",
        prop: "id",
        defaultAttr: {
          size: "small",
          label: "交易流水号",
          placeholder: "请输入交易流水号",
        },
      },
      {
        type: "dates",
        nameObj: {
          startTimeName: "workdate",
          endTimeName: "workdate2",
        },
        defaultAttr: {
          size: "small",
          label: "工作日期",
          placeholder: ["请输入工作开始日期", "请输入工作结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },
    ];
    this.formOptions = formOptions;
    this.dictMapAsync = this.getDictMap();
  },
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */
    /** 搜索按钮操作 */
    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      ccmsBusinessDownloadApplyQueryDetail(row).then((response) => {
        this.title = "参与机构业务管理状态下载申请报文查询明细";
        this.detailForm = row;
        this.queryParamsDetail.id = response.result.id;
        this.open = true;
      });
    },
  },
};
</script>
